import { Controller, Get, Post,Put, Body, Patch,Query, Param, Delete, Headers } from '@nestjs/common';
import { ChatMessageService } from './chatMessage.service';
import { ApiTags } from '@nestjs/swagger';
import {ChatMessageDto} from './dto/chatMessage.dto'
import { isNoAuth } from 'src/utils/decorator/jwt.decorator';
@ApiTags('聊天')
@Controller('chatmessage')
@isNoAuth()
export class ChatMessageController {
  constructor(private readonly chatMessageService: ChatMessageService) {}

  @Post("add")
  create(@Headers() header,@Body() chatMessageDto: ChatMessageDto) {
    // const dto = {...chatMessageDto, userId: header.userid, time: (new Date().getTime()).toString() }
    return this.chatMessageService.create(chatMessageDto);
  }

  @Get("search")
  async find(@Query() query):Promise<ChatMessageDto[]> {
    return  await this.chatMessageService.find(query.sessionId, query.id);
  }

  @Put('update/:id')
  update(@Param() param, @Body() chatMessageDto: ChatMessageDto) {
    return this.chatMessageService.update(param.id, chatMessageDto);
  }

  @Delete('del')
  remove(@Query() query):Promise<string> {
    return this.chatMessageService.remove(query.id);
  }

  @Get('list')
  list(@Headers() header, @Query() query):Promise<any> {
    return this.chatMessageService.list(query.page,query.pageSize);
  }
}
